package com.david.mydemo.framework.config;

import com.david.mydemo.util.SpringContextUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * 通用配置
 */
@Configuration
public class MyWebMvcConfig implements WebMvcConfigurer {

    @Autowired
    private MyInterceptor MyInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(MyInterceptor)
                // 拦截配置
                .addPathPatterns("/**")
                // 排除配置--对下面的不进行拦截
                .excludePathPatterns(
                        "/captcha/getCaptchaImage",
                        "/login/login",
                        "/login/appLogin",
                        "/login/logout",
                        "/login/refreshToken"
                );
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /** 文件上传路径 */
        registry.addResourceHandler("/profile/**")
                .addResourceLocations("file:" + SpringContextUtil.getEnvironmentProperty("customAttributes.profile"));
    }
}
